package org.example.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.pojo.Noise;
import org.example.pojo.NoiseCategory;
import org.example.pojo.Result;
import org.example.service.NoiseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/noises")
@CrossOrigin
public class NoiseController {
    @Autowired
    private NoiseService noiseService;
    
    @GetMapping
    public Result<List<Noise>> getAllNoises() {
        return Result.success(noiseService.getAllNoises());
    }
    
    @GetMapping("/categories")
    public Result<List<NoiseCategory>> getCategories() {
        return Result.success(noiseService.getAllCategories());
    }
    
    @GetMapping("/category/{categoryId}")
    public Result<List<Noise>> getNoisesByCategory(@PathVariable Integer categoryId) {
        return Result.success(noiseService.getNoisesByCategory(categoryId));
    }
} 